package com.example.administrator.wallet.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.ExchangeBalanceBean;
import com.example.administrator.wallet.view.activity.finds.kkbank.KKBankActivity;

import java.util.List;


/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/7/12.
 */
//KKBank
public class KKBankCoinAdapter extends BaseAdapter {
    private Context context;
    private List<ExchangeBalanceBean.DataBean.ListBean> iDatas;
    private int value = 1;
    private OnClick click;
    private String Currency = "";
    private String available = "";
    private Bt_kkbank_transfer_out_OnClick bt_kkbank_transfer_outclick;
    private Bt_kkbank_recharge_OnClick bt_kkbank_recharge_onClick;
    private int i;

    public KKBankCoinAdapter(KKBankActivity kKBankActivity, List<ExchangeBalanceBean.DataBean.ListBean> iDatas) {
        this.context = kKBankActivity;
        this.iDatas=iDatas;
    }

    @Override
    public int getCount() {
        return iDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(context, R.layout.list_coin_balance, null);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.iv_sign = (ImageView) view.findViewById(R.id.iv_sign);
        holder.tv_kk_balance = (TextView) view.findViewById(R.id.tv_kk_balance);
        holder.tv_currency = (TextView) view.findViewById(R.id.tv_currency);
        holder.bt_kkbank_recharge = (Button) view.findViewById(R.id.bt_kkbank_recharge);
        holder.bt_kkbank_transfer_out = (Button) view.findViewById(R.id.bt_kkbank_transfer_out);
        holder.rk_balance = (RelativeLayout) view.findViewById(R.id.rk_balance);
        holder.mRl_all = (RelativeLayout) view.findViewById(R.id.mRl_all);



        Glide.with(context).load(iDatas.get(i).getIcon()).into(holder.iv_sign);
        holder.tv_currency.setText(iDatas.get(i).getName());
        String  c = iDatas.get(i).getAvailable();
        holder.tv_kk_balance.setText(String.valueOf(c));

        Currency = iDatas.get(i).getName();
        available = iDatas.get(i).getAvailable();

        //余额详情跳转
        holder.rk_balance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                KKBankCoinAdapter.this.click.Click(iDatas.get(i));
//                Intent intent=new Intent(context,KKBankCurrencyBalanceActivity.class);
////                intent.putExtra("currency");
//                context.startActivity(intent);
            }
        });

        holder.bt_kkbank_transfer_out.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                KKBankCoinAdapter.this.bt_kkbank_transfer_outclick.Bt_kkbank_transfer_out_OnClick(iDatas.get(i));
//                Intent i = new Intent(context, CashWithdrawalOrRechargeActivity.class);
//                i.putExtra("title",String.valueOf(R.string.Cash_withdrawal));
//                i.putExtra("Currency", iDatas.get(i).getName());
//                i.putExtra("available", iDatas.get(i).getAvailable());
//                startActivity(i);

            }
        });
        holder.bt_kkbank_recharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                KKBankCoinAdapter.this.bt_kkbank_recharge_onClick.Bt_kkbank_recharge_OnClick(iDatas.get(i));
//                Intent i = new Intent(context, CashWithdrawalOrRechargeActivity.class);
//                i.putExtra("title",String.valueOf(R.string.recharge));
//                i.putExtra("Currency", Currency);
//                i.putExtra("available", available);
//                startActivity(i);

            }
        });


        return view;
    }

    public interface OnClick {
        void Click(ExchangeBalanceBean.DataBean.ListBean dataBean);
    }
    public interface Bt_kkbank_transfer_out_OnClick {
        void Bt_kkbank_transfer_out_OnClick(ExchangeBalanceBean.DataBean.ListBean dataBean);
    }
    public interface Bt_kkbank_recharge_OnClick {
        void Bt_kkbank_recharge_OnClick(ExchangeBalanceBean.DataBean.ListBean dataBean);
    }

    public void getClickPst(OnClick click) {
        this.click = click;
    }
    public void getBt_kkbank_transfer_outClickPst(Bt_kkbank_transfer_out_OnClick click) {
        this.bt_kkbank_transfer_outclick = click;

    }
    public void getBt_kkbank_recharge_OnClickPst(Bt_kkbank_recharge_OnClick click) {
        this.bt_kkbank_recharge_onClick = click;
    }


    public class ViewHolder {
        public ImageView iv_sign;//标志
        public TextView tv_currency,tv_kk_balance;//币种,余额
        public Button bt_kkbank_recharge,bt_kkbank_transfer_out;//充值,转出
        public RelativeLayout rk_balance,mRl_all;//余额详情,整体布局
    }
}
